<template>
  <div style="padding-left: 20px;padding-bottom: 20px;padding-right: 20px">
    <div style="display: flex; align-items: center; background: #EEF1F6;margin-bottom: 20px;padding-top: 20px" >

      <el-form :model="queryParams"  :inline="true" label-width="70px">
        <el-form-item label="仓库"  label-width="90px">
          <el-select v-model="queryParams.mineStatus" placeholder="请选择" multiple style="width: 200px">
            <el-option :value="queryParams.mineStatus" style="height: auto">
              <el-tree :data="treedata" default-expand-all show-checkbox check-strictly node-key="id"
                       ref="treeb" highlight-current :props="defaultProps"
                       @check-change="handleCheckChange"></el-tree>
            </el-option>
          </el-select>
        </el-form-item>



        <el-form-item label="编号" prop="deviceName">
          <el-input
            v-model="queryParams.deviceName"
            placeholder="请输入编号"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="名称" prop="deviceName">
          <el-input
            v-model="queryParams.deviceName"
            placeholder="请输入名称"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="规格型号" prop="deviceName">
          <el-input
            v-model="queryParams.deviceName"
            placeholder="请输入规格型号"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="" prop="deviceName">
          <el-button  type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button type="success" icon="el-icon-download" size="mini" @click="" >导出</el-button>
        </el-form-item>


      </el-form>
      <el-row>

      </el-row>
    </div>
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="4" :xs="24">

        <p>部件耗材分类树</p>
        <div class="head-container">
          <el-tree
            :data="deptOptionsNew"
            :props="defaultPropsb"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <!--用户数据-->
      <el-col :span="20" :xs="24">
        <div class="">
          <el-table  :data="deviceTypeList"  border>

            <el-table-column label="序号" type="index" width="55" align="center" />
            <el-table-column label="图片" align="center" prop="deviceCode" />
            <el-table-column align="center" label="产品编号" property="deviceCode" width="150" >
              <template slot-scope="scope" style="text-align: center">
                <span style="color: #2196F3;cursor: pointer" @click="xingqing(scope.row.deviceCode)">{{scope.row.deviceCode}}</span>
              </template>
            </el-table-column>
            <el-table-column label="产品名称" align="center" prop="deviceName" />
            <el-table-column label="分类" align="center" prop="parentId" />
            <el-table-column label="品牌" align="center" prop="parentId" />
            <el-table-column label="规格型号" align="center" prop="parentId" />
            <el-table-column label="所在仓库" align="center" prop="parentId" />
            <el-table-column label="单位" align="center" prop="parentId" />
            <el-table-column label="价格" align="center" prop="parentId" />
            <el-table-column label="平均价" align="center" prop="parentId" />
            <el-table-column label="数量" align="center" prop="parentId" />
          </el-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />

        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
  import request from '@/utils/request'
  import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user";
  import { listDeviceType, getDeviceType, delDeviceType, addDeviceType, updateDeviceType, exportDeviceType } from "@/api/device/deviceType";
  import { getToken } from "@/utils/auth";
  import { treeselect } from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    name: "User",
    components: { Treeselect },
    data() {
      return {
        mineStatus: "",
        treedata: [],
        defaultProps: {
          children: "children",
          label: "label"
        },
        defaultPropsb :{
          children: "children",
          label: "label"
        },


        imgchecked:false,//是否选择图片
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 设备类型表表格数据
        deviceTypeList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //类型数据
        lllxArr:[
          {value:'1',label:'安全库存预警'},
          {value:'2',label:'库存预测预警'}
        ],
        // 查询参数
        queryParams: {
          mineStatus:'',
          status:"1",//类型
          pageNum: 1,
          pageSize: 10,
          deviceCode: undefined,
          placeStorage: undefined,
          parentId: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
        // 部门树选项
        deptOptions: undefined,

        deptOptionsNew:undefined,
        // 部门名称
        deptName: undefined,
        // 状态数据字典
        statusOptions: [],
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      this.getList();
      this.getTreeselect();
    },
    methods: {
      handleCheckChange(data, checked, node) {

        var res =this.$refs.treeb.getCheckedNodes()
        console.log('res',res);
        var labelArr=[]
        var keyArr = []
        for (var i=0;i<res.length;i++ ){
          labelArr.push(res[i].label)
          keyArr.push(res[i].id)
        }
        console.log('labelArr',labelArr);
        console.log('keyArr',keyArr);
        this.queryParams.mineStatus = labelArr;
      },




      //详情
      xingqing:function(row){
        console.log(row)
        this.$router.push({path:"/consumable/tzXQ",query:{id:'12313213'}})

      },
      /** 删除按钮操作 */
      handleDelete(row) {
        this.$confirm('确定删除么?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      /** 查询用户列表 */
      getList() {
        this.loading = true;
        listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.userList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.treedata = response.data;
          this.deptOptionsNew = response.data;
          console.log('下拉数据',this.treedata)
        });
      },
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        console.log(data.id)
        this.queryParams.deptId = data.id;
        this.getList();
      },
      /** 查询设备类型表列表 */
      getList() {
        this.loading = true;
        listDeviceType(this.queryParams).then(response => {
          this.deviceTypeList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          deviceCode: undefined,
          deviceName: undefined,
          parentId: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        console.log('this.queryParams',this.queryParams)
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 添加 */
      resetQuery() {
        this.$router.push({path:'/consumable/jzAdd',query:{data:'31321321231'}});
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加设备类型表";
      },
      /** 编辑 */
      handleEdit(row) {
        this.$router.push({path:'/consumable/jzAdd',query:{data:row}});
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != undefined) {
              updateDeviceType(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            } else {
              addDeviceType(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            }
          }
        });
      },

    }
  };
</script>
